package io.yx.desktop;

import cn.hutool.core.io.resource.ResourceUtil;
import com.formdev.flatlaf.FlatDarkLaf;
import io.yx.desktop.ui.ControllerPanel;

import javax.swing.*;
import java.awt.*;

public class Main {
    public static final Image webIcon = new ImageIcon(ResourceUtil.getResource("web.png")).getImage();
    public static final Image webRunningIcon = new ImageIcon(ResourceUtil.getResource("web_running.png")).getImage();
    public static final TrayIcon trayIcon = new TrayIcon(webIcon, "startWeb");

    public static void main(String[] args) throws AWTException {
        FlatDarkLaf.setup();
        ControllerPanel controllerPanel = new ControllerPanel();
        controllerPanel.setVisible(true);
        SystemTray tray = SystemTray.getSystemTray();

        trayIcon.setImageAutoSize(true);
        trayIcon.addActionListener(e -> {
            controllerPanel.setVisible(true);
        });
        PopupMenu popup = new PopupMenu();
        MenuItem mi = new MenuItem("exit");
        mi.addActionListener(e -> {
            System.exit(0);
        });
        popup.add(mi);
        trayIcon.setPopupMenu(popup);
        tray.add(trayIcon);

    }
}